﻿app.filter('startFrom', function () {
    return function (input, start) {
        if (input) {
            start = +start; //parse to int
            return input.slice(start);
        }
        return [];
    }
});
app.controller('NotificationController', ['$scope', 'GlobalService', 'ApplicationService', 'alertboxservice', 'fileUpload', function ($scope, GlobalService, ApplicationService, alertboxservice, fileUpload) {

    BindGrid();

    $scope.result = 0;

    $scope.Refresh = function () {
        url = "Notification/UpdateControllers";
        ApplicationService.Getdata(url).success(function (data) {
            $scope.result = data;
        });
    }
    var Priorityobj1 = {
        PriorityId: 0,
        PriorityName: "Low"
    }
    var Priorityobj2 = {
        PriorityId: 1,
        PriorityName: "Medium"
    }
    var Priorityobj3 = {
        PriorityId: 2,
        PriorityName: "High"
    }
    $scope.Priority = [];
    $scope.Priority.push(Priorityobj1);
    $scope.Priority.push(Priorityobj2);
    $scope.Priority.push(Priorityobj3);
    function BindGrid() {
        url = "Notification/GetControllers";
        ApplicationService.Getdatas(url).success(function (data) {
            $scope.list = data;
            $scope.currentPage = 1;
            $scope.entryLimit = 10;
            $scope.filteredItems = $scope.list.length;
            $scope.totalItems = $scope.list.length;
        });
    }

    $scope.toggle = function (modelstate, Id) {

        $scope.modelstate = modelstate;
        $scope.id = Id;
        switch (modelstate) {
            case 'add':
                $scope.title = "Add Church Details";
                $scope.church = null;
                break;
            case 'edit':
                $scope.title = "Edit Funcation Details";
                url = "Notification/GetController";
                ApplicationService.Getdata(url, Id).success(function (data) {
                    $scope.notification = data;
                });
                break;
        }
        $("#notification").modal({ backdrop: 'static' });
    }


    $scope.setPage = function (pageNo) {
        $scope.currentPage = pageNo;
    };

    $scope.sort_by = function (predicate) {
        $scope.predicate = predicate;
        $scope.reverse = !$scope.reverse;
    };


    $scope.save = function (modelstate, id) {
        $scope.buttonstate = true;
        var url;
        switch (modelstate) {
            case 'add':
                url = "Notification/SaveChurchDetails";
                break;
            case 'edit':
                url = "Notification/UpdateControllerDetails";
                break;
        }
        ApplicationService.Save($scope.notification, url).success(function (result) {
            alertboxservice.ShowMsg(result, "notification ");
            $scope.buttonstate = false;
            BindGrid();
        });
    }

}]);

